#define _CRT_SECURE_NO_WARNINGS 1

#include <iostream>
using namespace std;

const int N = 110;
int n, d;
int a[N][N];

int get(int stx,int sty,int x, int y)
{
    int lx = stx, ly = sty, rx = stx, ry = sty;

    int sum = 0, res = 0;
    while (rx < n && ry < n && rx >= 0 && ry >= 0)
    {
        while (rx - lx + 1 > d || ry - ly + 1 > d)
        {
            sum -= a[lx][ly];
            lx += x;
            ly += y;
        }

        sum += a[rx][ry];
        if (rx - lx + 1 == d || ry - ly + 1 == d)
            res = max(res, sum);

        rx += x;
        ry += y;
    }
    return res;
}

int main()
{
    cin >> n >> d;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
        {
            cin >> a[i][j];
        }

    int res = 0;
    for(int i = 0;i < n;i++)
        for (int j = 0; j < n; j++)
        {
            res = max(res, get(i,j,0, 1));
            res = max(res, get(i, j, 1, 0));
            res = max(res, get(i, j, 1, 1));
            res = max(res, get(i, j, 1, -1));
        }

    cout << res << endl;
    return 0;
}